import uuid
import jsonschema

from jsonschema import validate
from service import json_format

from service.func.file_load import file_load
from Connector.client import res_success


class CmdFileLoad:
    name = "file_load"
    id = uuid.uuid4()

    def __init__(self, service, Params, Tag, Type):
        self.service = service
        self.params = Params
        self.tag = Tag
        self.type = Type

    async def execute(self):
        uid = file_load(self.service, self.params)
        await res_success(self.tag, self.type, {"status": "success", "uid": uid})

        # try:
        #     validate(instance=self.params, schema=json_format.format_cmd_file_load)
        #     file_load(self.service, self.params)
        #     await res_success(self.params.get("Tag"), self.type, 1)
        # except jsonschema.exceptions.ValidationError as e:
        #     print("数据无效")
